package com.example.seckilldemo.rabbitmq;


import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MQSender {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendSeckillMessage(String message){
        log.info("发送消息："+ message);
        rabbitTemplate.convertAndSend("seckillExchange", "seckill.message", message);
    }
    /*
    public void send(Object msg){
        log.info("发送消息" + msg);
        rabbitTemplate.convertAndSend("fanoutExchange","",msg);
    }

    public void sendD1(Object msg){
        log.info("发送red消息" + msg);
        rabbitTemplate.convertAndSend("directExchange","queue.red",msg);
    }
    public void sendD2(Object msg){
        log.info("发送green消息" + msg);
        rabbitTemplate.convertAndSend("directExchange","queue.green",msg);
    }

    public void sendT1(Object msg){
        log.info("发送QUEUE01接收消息" + msg);
        rabbitTemplate.convertAndSend("topicExchange","queue.red.message",msg);
    }
    public void sendT2(Object msg){
        log.info("发送1和2接收消息" + msg);
        rabbitTemplate.convertAndSend("topicExchange","message.queue.green.abc",msg);
    }


    public void sendH01(String msg){
        log.info("发送消息Headers(QUEUE01接收)：" + msg);
        MessageProperties properties = new MessageProperties();
        properties.setHeader("color", "red");
        properties.setHeader("speed", "normal");
        Message message = new Message(msg.getBytes(), properties);
        rabbitTemplate.convertAndSend("headersExchange", "", message);
    }
    public void sendH02(String msg){
        log.info("发送消息Headers(两个QUEUE接收)：" + msg);
        MessageProperties properties = new MessageProperties();
        properties.setHeader("color", "red");
        properties.setHeader("speed", "fast");
        Message message = new Message(msg.getBytes(), properties);
        rabbitTemplate.convertAndSend("headersExchange", "", message);
    }
     */
}
